<?php

/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2017/6/28
 * Time: 14:38
 */

namespace Admin\Service;

use Service\BaseService;

class FinanceService extends BaseService {



    public function __construct() {
        parent::__construct();
        $this->financeModel = M('pay_log');
    }

    public function logList($username,$mobile,$type = 0,$isPage = 1, $nowPage = 1) {
        if($type)
            $where['al.type'] = $type;

        if ($username) {
            $where['au.username'] = array('like', '%'.$username.'%');
        }
        if ($mobile) {
            $where['au.mobile'] = $mobile;
        }

        $where['al.au_id'] = array('gt', 0);
        $obj = $this->financeModel->alias('al')
            ->field('al.*,au.username,au.mobile,u.username as pay_user,u.mobile as pay_mobile')
            ->join(' LEFT JOIN ' . C('DB_PREFIX') . 'accountant_users AS au ON au.au_id = al.au_id')
            ->join(' LEFT JOIN ' . C('DB_PREFIX') . 'users AS u ON al.user_id = u.user_id')
             ->order('al.id desc');

        if ($where) {
            $obj->where($where);
        }
        if ($isPage) {
            $countRes = $obj->count();
            self::bPage($countRes);
            return self::resReturn(200, "success", self::$pageObj);
        } else {
            $lineList = $obj->page($nowPage, self::$pageNum)->select();
            return self::resReturn(200, 'success', $lineList);
        }
    }


    public function tradeList($username,$mobile,$type = 0,$isPage = 1, $nowPage = 1) {
        if($type)
            $where['al.type'] = $type;

        if ($username) {
            $where['au.username'] = array('like', '%'.$username.'%');
        }
        if ($mobile) {
            $where['au.mobile'] = $mobile;
        }

        $where['al.au_id'] = array('gt', 0);
        $obj = M('accountant_log')->alias('al')
            ->field('al.*,au.username,au.mobile')
            ->join(' LEFT JOIN ' . C('DB_PREFIX') . 'accountant_users AS au ON au.au_id = al.au_id')
            ->order('al.id desc');

        if ($where) {
            $obj->where($where);
        }
        if ($isPage) {
            $countRes = $obj->count();
            self::bPage($countRes);
            return self::resReturn(200, "success", self::$pageObj);
        } else {
            $lineList = $obj->page($nowPage, self::$pageNum)->select();
            return self::resReturn(200, 'success', $lineList);
        }
    }




}
